//
//  URLCache+Extension.swift
//  MT
//
//  Created by zhang qiang on 2018/11/21.
//  Copyright © 2018年 张强. All rights reserved.
//

import Foundation
import WebKit


public extension URLCache {
    static func removeCache() {
        let version = Double(UIDevice.current.systemVersion.components(separatedBy: ".").first!)!
        if  version >= 9.0 {
            let websiteDataTypes = NSSet(array: [
                WKWebsiteDataTypeDiskCache,
                //WKWebsiteDataTypeOfflineWebApplication
                WKWebsiteDataTypeMemoryCache,
                WKWebsiteDataTypeLocalStorage,
                WKWebsiteDataTypeCookies,
                //WKWebsiteDataTypeSessionStorage,
                //WKWebsiteDataTypeIndexedDBDatabases,
                //WKWebsiteDataTypeWebSQLDatabases
                ])
            
            let dateForm = NSDate(timeIntervalSince1970: 0)
            
            WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes as! Set<String>, modifiedSince: dateForm as Date, completionHandler: {
                
            })
            
            URLCache.shared.removeAllCachedResponses()
        }
    }
}
